<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/js/web/frame/jedate/skin/jedate.css')}}">
    <link rel="stylesheet" href="{{asset('/css/web/user/prove_release.css')}}">
    <script src="{{asset('/js/web/frame/jedate/jquery.jedate.js')}}"></script>
    <link rel="stylesheet" href="{{asset('/css/web/user/order_list.css')}}">
    <script src="{{asset('/js/web/user/order_list.js')}}"></script>
    <link rel="stylesheet" href="{{asset('/css/web/inc/header.css')}}">
    <link rel="stylesheet" href="{{asset('/css/web/user/service_orders.css')}}">
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.buyer_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">我的订单</div>
                <div class="my-subnav ">
                    <ul>
                        <li class="@if(empty($search_params['status'])) cur @endif">
                            <a href="{{asset('/member/buyer/service/order')}}" class="jm_hover">所有订单</a><i></i>
                        </li>
                        <li class="@if($search_params['status']==1) cur @endif">
                            <a href="{{asset('/member/buyer/service/order?status=1')}}" class="jm_hover">待订单确认</a><i></i>
                        </li>
                        <li class="@if($search_params['status']==2) cur @endif">
                            <a href="{{asset('/member/buyer/service/order?status=2')}}" class="jm_hover">待付款</a><i></i>
                        </li>
                        <li class="@if($search_params['status']==3) cur @endif">
                            <a href="{{asset('/member/buyer/service/order?status=3')}}" class="jm_hover">待交付确认</a><i></i>
                        </li>
                        <li class="@if($search_params['status']=='41,42,5') cur @endif">
                            <a href="{{asset('/member/buyer/service/order?status=41,42,5')}}" class="jm_hover">待评价</a><i></i>
                        </li>
                        <li class="@if($search_params['status']==6) cur @endif">
                            <a href="{{asset('/member/buyer/service/order?status=5')}}" class="jm_hover">完成</a><i></i>
                        </li>
                    </ul>
                </div>
                <div class="search f-cb">
                    <form action="{{asset('/member/buyer/service/order')}}" method="GET">
                        <input name='keyword' type="text" class="text fl" placeholder="服务名称/订单编号/商家名称" value='{{array_get($search_params,'keyword')}}'>
                        <div class="time fl">
                            下单时间：
                            <input value='{{array_get($search_params,'created_at.start')}}' name='created_at[start]' type="text" class="timetext workinput wicon" id="inpstart" readonly />
                            <span>至</span>
                            <input value='{{array_get($search_params,'created_at.end')}}' name='created_at[end]' type="text" class="timetext workinput wicon" id="inpend" readonly>
                        </div>
                        <input type="submit" class="submit fr" value="查询">
                    </form>
                </div>
                <div class="content">
                    <div class="table list" style="border: 1px solid #e6e6e6;border-bottom:0;margin-top: 20px;">
                        <table>
                            <thead>
                                <tr style="border-bottom: 1px solid #e6e6e6;">
                                    <th width="120">订单编号</th>
                                    <th width="194">服务名称</th>
                                    <th width="164">服务企业</th>
                                    <th width="120">费用类型</th>
                                    <th width="120">金额</th>
                                    <th width="120">状态</th>
                                    <th width="120">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            @foreach($list as $key=>$value)
                                <?php $count = count($value['order_products']) ?>

                                @foreach($value['order_products'] as $k=>$v)
                                    @if($k==0)
                                        <tr>
                                            <td style="border-right: 1px solid #e6e6e6;" rowspan="{{$count}}">{{$value['order_code']}}</td>
                                            <td style="border-right: 1px solid #e6e6e6;" rowspan="{{$count}}">{{$value['order_qualification']['project_name']}}</td>
                                            <td style="border-right: 1px solid #e6e6e6;" rowspan="{{$count}}">{{array_get($value,'shop.sp_name')}}</td>

                                            <td style="border-right: 1px solid #e6e6e6;">{{array_get($v,'product_name')}}</td>

                                            <td style="color:#ff7a00;border-right: 1px solid #e6e6e6;">¥{{$v['product_price']}}</td>
                                            <td style="border-right: 1px solid #e6e6e6;" rowspan="{{$count}}">
                                                {{--交易状态; 1:等待付款，2: 付款完成 3: 已发货 4:确认完成 5:已取消--}}
                                                @if($value['order_status'] == 1)
                                                      @if($value['order_qualification']['status']==1)
                                                        <div>待卖家确认</div>
                                                    @elseif($value['order_qualification']['status'] == 2)
                                                        <div>待订单确认</div>
                                                        @elseif($value['order_qualification']['status'] ==3)
                                                        <div>待付款</div>
                                                    @endif

                                                @elseif($value['order_status'] == 2)
                                                    <div>待发货</div>
                                                @elseif($value['order_status'] == 3)
                                                    <div>待确认收货</div>
                                                @elseif($value['order_status'] == 5)
                                                    <div>待评价</div>
                                                @elseif($value['order_status'] == 6)
                                                    <div>交易完成</div>
                                                @elseif($value['order_status'] == 7)
                                                    <div>已取消</div>
                                                @endif
                                                @if($value['order_qualification']['is_deposit']==2)
                                                    @if($value['order_qualification']['status'] == 41)
                                                        <div>退保证金中</div>
                                                    @elseif($value['order_qualification']['status'] == 42)
                                                        <div>退保证金中(等待卖家确认)</div>
                                                    @endif
                                                @endif
                                            </td>
                                            {{--交易状态 1. 待卖家确认 2.待付款(签署合同付款)  3.待交付(盖章) 41. 待申请退保证金 42.确认退保证金 5.待评价 6.已完成 7.已取消--}}
                                            <td rowspan={{$count}}>
                                                <div class="btnbox">
                                                <span class="btn_eidt" data-title="{{$value['order_qualification']['project_name']}}" data-id="{{$value['id']}}" data-time="{{$value['order_qualification']['expect_date']}}" data-msg="{{$value['remark']}}" data-type="1">
                                                    备注
                                                </span>
                                                 @if($value['order_status'] == 1)

                                                    @if($value['order_qualification']['status'] == 2)
                                                        <a href="javascript:;" data-id='{{$value['id']}}' data-qid="{{$value['order_qualification']['id']}}" class="btn jm_btn8 sign qsht">签署合同并付款</a>
                                                    @elseif($value['order_qualification']['status']==3)
                                                       <a href="{{asset('/member/buyer/order_contract/contract_write?order_id=')}}{{$value['id']}}" data-id='{{$value['id']}}' class="btn jm_btn8 sign" >付款</a>
                                                    @endif

                                                    @if($value['order_qualification']['status']<3)
                                                        <a href="javascript:;" class="order_cancel" data-id="{{$value['id']}}">取消</a>
                                                    @endif
                                                @else

 												@endif
                                                <!-- <div class="make" data-id="">实施</div> -->
                                                <!-- <a href="javascript:;" class="logistics_info" data-id="">查看物流</a> -->
                                                </div>
                                            </td>
                                        </tr>
                                    @endif
                                    @if($k>0)
                                        <tr>
                                            <td style="border-right: 1px solid #e6e6e6;">{{$v['product_name']}}</td>
                                            <td style="color:#ff7a00;border-right: 1px solid #e6e6e6;">¥{{$v['product_price']}}</td>
                                        </tr>
                                    @endif
                                @endforeach
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="page">
                    @include('web.common.paginate', ['page' => $page])
                </div>
            </div>

        </div>
    </div>
</div>
<div class="bg_h"></div>
<div class="banner_bombbox">
    <div class="h_top"><h2>备注</h2><a class="close_box">×</a></div>
    <input type="hidden" name="screen_type">
    <input type="hidden" name="id">
    {{--<div class="fl shu_box mt30">--}}
        {{--<span>期望交付时间</span>--}}
        {{--<input type="text" name="project_time" class="project_time" placeholder="例：2018/07/01">--}}
        {{--<p class="jm_error"></p>--}}
    {{--</div>--}}
    <div class="fl shu_box">
        <span>项目名</span>
        {{--<input type="text" name="project_title" title="" class="project_title">--}}
        <span id="project_title" style="text-align:left;"></span>
        <p class="jm_error"></p>
    </div>
    <div class="fl shu_box">
        <span>备注信息</span>
        <textarea name="project_msg" id="" title="备注信息" placeholder="请输入需要告知卖家的备注信息" class="project_msg"></textarea>
        <p class="jm_error"></p>
    </div>
    {{--<div class="fl shu_box">--}}
        {{--<span>附件</span>--}}
        {{--<input type="file" name="project_file" id="btn_uploadimg" class="project_file">--}}
        {{--<p class="jm_error"></p>--}}
    {{--</div>--}}
    <div class="btn_box">
        <div class="btn_confirm delivery_confirm">确定</div>
        <div class="btn_cancel close_box">取消</div>
    </div>
</div>
<form id="uploadForm" action="{{url('uploads/images')}}" method="post">
    {{csrf_field()}}
    <input style="display: none;" name="file" type="file" class="inputFile" />
</form>

{{--评价--}}
<div class="revise_evaluate_bombbox" id='evaluate_bombbox'>
</div>
@include('web.layout.footer')
<script type="text/javascript">
    //url定义
    var express_url = "/member/seller/orders/{id}/order_express/0";
    var order_update = '/member/buyer/orders/{id}';
    var order_cancel = "";
    var comment_url = '/member/seller/orders/{id}/user_comment/0';
	var sign_url = '/member/buyer/order_contract/contract_write?order_id={id}&qid={qid}';
    $(".qsht").on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
        var order_id = $(this).data('id');
        var qid = $(this).data('qid');
        var url = sign_url.replace('{id}', order_id).replace('{qid}', qid);
        $.ajax({
            url: url,
            type: 'GET',
            dataType: 'json',
            data: {},
            success:function(data){
              if(0==data.status){
            	  if(data.code == 1){
                      window.location.href='/member/buyer/order_contract/contract_auth';
                  }else{
                	  layer.alert(data.msg, {
                          icon: 0
                      });
                  }
              }else{
            	  window.location.href=url;
              }
            },
            error:function(data){
            	window.location.href=url;
            },
        });

    });

    $(".order_cancel").on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
        var order_id = $(this).data('id');
        var url = '/member/buyer/service/order/close/{id}'.replace('{id}', order_id);
        layer.confirm('是否取消？', {
            btn: ['确认', '取消'] //可以无限个按钮
        }, function (index) {
            $.ajax({
                url: url,
                type: 'GET',
                dataType: 'json',
                data: {order_status: 5},
                success:function(data){
                  if(0==data.code){
                      layer.alert('取消成功！', {
                          icon: 1
                      }, function () {
                          window.location.reload();
                      });
                  }else{
                    alert(data.message);
                  }
                }
            });
        }, function (index, layero) {
            layer.close(index);
        });

    });

    $(".seal_confirm").on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
        var order_id = $(this).data('id');
        var url = order_update.replace('{id}', order_id);
        layer.confirm('是否确认盖章？', {
            btn: ['确认', '取消'] //可以无限个按钮
        }, function (index) {
            $.ajax({
                url: url,
                type: 'PUT',
                dataType: 'json',
                data: {order_status: 5},
                success:function(data){
                  if(0==data.code){
                      layer.alert('取消成功！', {
                          icon: 1
                      }, function () {
                          window.location.reload();
                      });
                  }else{
                    alert(data.message);
                  }
                }
            });
        }, function (index, layero) {
            layer.close(index);
        });

    });
    $(".make").on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
        var order_id = $(this).data('id');
        var url = order_update.replace('{id}', order_id);
        layer.confirm('是否实施？', {
            btn: ['确认', '取消'] //可以无限个按钮
        }, function (index) {
            $.ajax({
                url: url,
                type: 'PUT',
                dataType: 'json',
                data: {order_status: 5},
                success:function(data){
                  if(0==data.code){
                      layer.alert('取消成功！', {
                          icon: 1
                      }, function () {
                          window.location.reload();
                      });
                  }else{
                    alert(data.message);
                  }
                }
            });
        }, function (index, layero) {
            layer.close(index);
        });

    });
    $(".order_confirm").on('click', function(event) {
        event.preventDefault();
        var order_id = $(this).data('id');
        console.log(order_id)
        var url = order_update.replace('{id}', order_id);
        layer.confirm('是否申请退还保证金？', {
            btn: ['确认', '取消'] //可以无限个按钮
        }, function (index) {
            /* Act on the event */
            $.ajax({
                url: url,
                type: 'put',
                dataType: 'json',
                data: {order_status:4},
                success:function(data){
                    if(0==data.code){
                        window.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            });
        }, function (index, layero) {
            layer.close(index);
        });
    });

    $(function () {
        //申请退款
        $(".apply_refund").on('click', function(event) {
            event.preventDefault();
            /* Act on the event */
            var order_code = $(this).data('code');
            layer.confirm('是否确认退款？', {
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (index) {
                $.ajax({
                    url: 'order_apply_refund',
                    type: 'GET',
                    dataType: 'json',
                    data: {order_code: order_code},
                    success:function(data){
                        if(0==data.code){
                            window.location.reload();
                        }else{
                            alert(data.message);
                        }
                    }
                });
            }, function (index, layero) {
                layer.close(index);
            });
        });

        //申请退货
        $(".apply_sales_return").on('click', function(event) {
            event.preventDefault();
            /* Act on the event */
            var order_code = $(this).data('code');
            layer.confirm('是否确认退货？', {
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (index) {
                $.ajax({
                    url: 'order_apply_sales_return',
                    type: 'GET',
                    dataType: 'json',
                    data: {order_code: order_code},
                    success:function(data){
                        if(0==data.code){
                            window.location.reload();
                        }else{
                            alert(data.message);
                        }
                    }
                });
            }, function (index, layero) {
                layer.close(index);
            });

        });

        //评价
        $('.revise_evaluate').click(function(){
            var order_id = $(this).data('id');
            var url = comment_url.replace('{id}', order_id);
            $.ajax({
                url: url,
                type: 'get',
                dataType: 'html',
                success: function (data) {
                    $('.revise_evaluate_bombbox').html(data);
                    $('.revise_evaluate_bombbox').show();
                    $('.bg_h').show();
                }
            });
        });
    })
$(function(){
    var _token = '{!! csrf_token() !!}';
    //备注
    $('.btn_eidt').click(function(){
        var id = $(this).attr('data-id');
        //var src = $(this).attr('data-src');
        var time = $(this).attr('data-time');
        var name = $(this).attr('data-title');
        var msg = $(this).attr('data-msg');
        //var type = $(this).attr('data-type');

        // input 赋值
        $("input[name=id]").val(id);
        $("input[name=project_time]").val(time);
//        $("input[name=project_title]").val(name);
        $('#project_title').html(name);
        $(".project_msg").val(msg);
        // $("input[name=screen_type]").val(type);
        // $("#btn_uploadimg").attr('src',src);

        // $(".project_file").val(src);

        $('.bg_h').show();
        $('.banner_bombbox').show();
    });
    $('.close_box').click(function(){
        // 清空值
        $("input[name=id]").val('');
        $("input[name=project_time]").val('');
        $("input[name=project_title]").val('');
        $(".project_msg").val('');
        $(".project_file").val('');
        $('.jm_error').html('');

        $('.bg_h').hide();
        $('.banner_bombbox').hide();
    });

    $('.delivery_confirm').click(function(){
        var id = $("input[name=id]").val();

        $('.jm_error').html('');
//        var project_time = $(".project_time");
//        if(project_time.val() == ''){
//            project_time.parent().find('.jm_error').html('请输入交付时间');
//            return false;
//        }
        var project_msg = $(".project_msg");
        if(project_msg.val() == ''){
            project_msg.parent().find('.jm_error').html('请输入需要告知卖家的备注信息');
            return false;
        }

        var url='';
        var ajaxType = 'POST';
        if (id){
            url = '/member/buyer/service/order/'+id;// update
            ajaxType = 'PUT';
        }else{
            layer.alert("保存失败", {
                icon: 2
            }, function (index) {
                // location.reload();
                layer.close(index);
            });
            return false;
        }
//        var expect_date = project_time.val();
        var remark = project_msg.val();
//        console.log(expect_date);
        console.log(remark);
        $.ajax({
            url: url,
            type: 'PUT',
            data: {remark:remark},
            success: function (res) {
                if (res.code == 0){
                      layer.alert("保存成功", {
                          icon: 1
                      }, function () {
                          location.reload();
                      });
                } else {
                    layer.alert('保存失败', {
                        title:'错误提示',
                        icon: 2
                    });
                }
            },
            error: function () { }
        });
    });


    // 文件上传点击
    // $('#btn_uploadimg').click(function () {
    //     $('.inputFile').trigger('click');
    // });
    // 选择完要上传的文件后, 直接触发表单提交
    $('input[name=file]').on('change', function () {
        if ($.trim($(this).val())) {
            $("#uploadForm").trigger('submit');
        }
    });

    // 文件上传
    $("#uploadForm").on('submit', function (e) {
        e.preventDefault();
        $.ajax({
            url: "{{url('uploads/images')}}",
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            // 显示加载图片
            success: function (res) {
                if (res.status == 0){
                    var img_path = '' + res.path;
                    $(".project_file").val(res.path);
                    $("#btn_uploadimg").attr('src',res.path)
                } else {
                    layer.alert('文件上传失败', {
                        title:'提示',
                        icon: 2
                    });
                }
            },
            error: function () { }
        });
    });
})
</script>
</body>
</html>